
export function toast(message) {
    uni.showToast({
        title: message,
        icon: 'none',
        duration: 2000
    })
}

export function checkMobile(value) {
  return /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value)
}

export function joinRequestData(data) {
    const requestSortData = []
    Object.keys(data).sort().map(key => {
        const dataType = typeof data[key]
        if (dataType !== 'object' && dataType !== 'array' && dataType !== 'undefined') {
            requestSortData.push(key + '=' + data[key])
        }
    })
    return requestSortData.join('&')
}
export function formatSeconds(value) { // 将秒转化为 时：分：秒,可用于计时
	if (!value) {
		return '00:00:00'
	}
	let result = parseInt(value)
	const h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600)
	const m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60))
	const s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60))
	result = `${h}:${m}:${s}`
	return result
}
// 获取当前日期，格式YYYY-MM-DD hh:mm:ss，将当前时间转换成年月日时分秒
 export function getNowFormatTime () {
  const now = new Date()
  const year = now.getFullYear() // 获取完整的年份(4位,1970-????)
  const month = now.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
  const today = now.getDate() // 获取当前日(1-31)
  const hour = now.getHours() // 获取当前小时数(0-23)
  const minute = now.getMinutes() // 获取当前分钟数(0-59)
  const second = now.getSeconds() // 获取当前秒数(0-59)
  let nowTime = ''
  nowTime = year + '-' + fillZero(month) + '-' + fillZero(today) + ' ' + fillZero(hour) + ':' +
    fillZero(minute) + ':' + fillZero(second)
  return nowTime
}

function fillZero (str) {
  var realNum
  if (str < 10) {
    realNum = '0' + str
  } else {
    realNum = str
  }
  return realNum
}
// 获取当前日期，格式YYYY-MM-DD
export function getNowFormatDay(nowDate) {
    const char = '-'
    if (nowDate == null) {
        nowDate = new Date()
    }
    const day = nowDate.getDate()
    const month = nowDate.getMonth() + 1 // 注意月份需要+1
    const year = nowDate.getFullYear()

    function completeDate(value) {
        return value < 10 ? '0' + value : value
    }
    // 补全0，并拼接
    return year + char + completeDate(month) + char + completeDate(day)
}
